<template>
	<z-paging class="wrap" ref="paging" v-model="dataList" @query="queryList">
		<cu-custom bgColor="bg-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{title}}</block>
		</cu-custom>
		<view class="search">
			<u-search placeholder="请输入关键词" v-model="getData.KeyWord"  @custom='search()' @search='search()'></u-search>
		</view>
		<spareparts v-bind:dataList='giveList'></spareparts>
	</z-paging>
</template>

<script>
	import request from '@/common/request.js';
	import spareparts from "@/components/spareparts/spareparts.vue"
	export default {
		components:{
			spareparts
		},
		data(){
			return{
				giveList:[],
				type:1,
				title:'',
				dataList:[],
				getData:{
					ETArchivesId:'',
					KeyWord:'',
					PageIndex:1,
					PageSize:10,
					Sort: 'AddTime',
					SortType: 'desc',
				},
			}
		},
		onLoad(options) {
			var that=this
			that.type=options.type
			if(options.type==1){
				that.title='附属备件'
			}else{
				that.title='附件、工卡、器具'
			}
			that.deviceId=options.deviceId
			that.getData.ETArchivesId=options.deviceId
			that.giveList=[
			]
		},
		methods:{
			queryList(pageNo, pageSize) {
				var that = this;
				uni.showLoading({
					title: '加载中...'
				})
				let url=''
				if(that.type==1){
					url='cofcoApi/GetETBJAndFSPageList'
				}else{
					url='cofcoApi/GetETFJAndGKPageList'
				}
				let opts = {
					url: url,
					method: 'get'
				};
				that.getData.PageIndex=pageNo;
				that.getData.PageSize=pageSize;
				request.httpRequest(opts,that.getData).then(res => {
					if(res.data.code == 1){
						this.$refs.paging.complete(res.data.data.Data);
						that.giveList=res.data.data.Data;
						uni.hideLoading();
					}
					else{
						uni.showToast({ title: res.data.msg, icon: 'none' });
					}
				});
			},
			// 查看设备维修详情
			seeMaintainInfo(e){
				//维修详情的id
				let id=e
				uni.navigateTo({
					url:'/pages-device/repair/maintainInfo?repairId='+id
				})
			},
			// 搜索框
			search(e){
				let that=this
				that.getData.PageIndex=1;
				that.getData.PageSize=10;
				that.getData.KeyWord=e
				this.queryList(1,10);
			}
		}
	}
</script>

<style lang="scss">
.search{
	width: 100%;
	height: 100rpx;
	padding: 20rpx 2% 0 2%;
	background-color: #fff;
}
</style>